package com.hy.example.shared.distribute.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;

/**
 * 委托实现 分布式读写锁
 */
public class DelegatingReadWriteLock implements DistReadWriteLock {
    private final Lock readLock;
    private final Lock writeLock;

    public DelegatingReadWriteLock(ReadWriteLock readWriteLock) {
        this.readLock = new DelegatingLock(readWriteLock.readLock());
        this.writeLock = new DelegatingLock(readWriteLock.writeLock());
    }

    @Override
    public Lock readLock() {
        return readLock;
    }

    @Override
    public Lock writeLock() {
        return writeLock;
    }
}
